/* 
 * File:   Parallellogram.cpp
 * Author: lgr013
 * 
 * Created on 13 de septiembre de 2014, 12:12
 */

#include "Parallellogram.h"

Parallellogram::Parallellogram() {
}

Parallellogram::Parallellogram(ObjFactory *objFactory, bool flagStatic, float x, float y, float base, float height, double alpha, float mass, float rotation, int idImage) {
    SBSLog* myLogFile;
    myLogFile->getInstance(MY_LOG_MODE);

    if (height <= 0 || base <= 0){
        myLogFile->writeInLog(2, "[2] Tamaño de paralelogramo invalido\n");                
    }
    
    Dot *dot = new Dot(x,y,base,height);   

    Object* object = objFactory->getObjectParallellogram(flagStatic, dot->dotPixelsToWorld(), dot->sizeDotPixelsToWorld(), alpha, mass, rotation);
    this->object = object;    
    
    struct ObjectInit auxData;
    auxData.objectId = PARALLELOGRAM;
    auxData.imageId = idImage;
    auxData.estatico = flagStatic;
    auxData.x = x;
    auxData.y = y;
    auxData.height = height;
    auxData.width = base + (height / tan(M_PI/4));
    auxData.rot = rotation;
    
    auxData.idCharacter = VACIO;
    auxData.stateCharacter = VACIO;
    
    this->data = auxData;

    myLogFile->writeInLog(0, "[0] Se ha creado un paralelogramo exitosamente\n");                
    this->equals = false;
    delete dot;
}

void Parallellogram::checkChanges(){
    b2Vec2 pos = this->object->getPosition();
    if (this->data.x == pos.x && this->data.y == pos.y && this->data.rot  == this->object->getAngle()){
        this->equals = true;        
    }else{
        this->equals = false;        
    }

}

void Parallellogram::restartPlayer(){}

void Parallellogram::updateData(){
    this->updatePosition();
    this->updateRotation();
}

void Parallellogram::updateRotation(){
    this->data.rot = this->object->getAngle();
}

void Parallellogram::updatePosition(){    
    b2Vec2 pos = this->object->getPosition();
    this->data.x = pos.x;
    this->data.y = pos.y;
    
}

struct ObjectInit Parallellogram::getData(){
    this->updateData();
    return this->data;
}

void Parallellogram::setUbicDyn(int id){
    this->data.ubicDyn = id;
}

b2Vec2 Parallellogram::getPosition(){
    return this->object->getPosition();
}

float Parallellogram::getAngle(){
    return this->object->getAngle();
}

float Parallellogram::getAngularVelocity(){
    return this->object->getAngularVelocity();
}

void Parallellogram::setAngularVelocity(float velocity){
    this->object->setAngularVelocity(velocity);
}

bool Parallellogram::getAreEquals(){
    return this->equals;
}
b2Body* Parallellogram::getBody() {
    return this->object->getBody();    
}
Parallellogram::~Parallellogram() {
    delete this->object;
//    printf("destructor Paralelogramo \n");
}
